package kr.pe.johnkim.chattingday.mobile.rest.controller;

import kr.pe.johnkim.chattingday.mobile.domain.ChattingDayMember;
import kr.pe.johnkim.chattingday.mobile.rest.service.ChattingDayMemberService;
import kr.pe.johnkim.chattingday.mobile.util.ChattingDayCommon;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

/**
 * Chatting Day 사용자 관련 Controller 클래스 이다.
 * 
 * @author : johnkim <cale9797@gmail.com / Bettersoft Inc,.>
 * @Date : 12. 5. 16
 */

@Controller
@Path("/chattingDayMemberController")
public class ChattingDayMemberController {

    // SLF4J Logging
	private Logger logger = LoggerFactory.getLogger(ChattingDayMemberController.class);

    @Autowired
    private ChattingDayMemberService chattingDayMemberService = null;

    @Autowired
    private ChattingDayCommon chattingDayCommon = null;

    /**
     * 사용자 등록을 위해서 아이디 중복 검사를 한다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/checkIdDuplication")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember checkIdDuplication(InputStream is) throws Exception {
        logger.info("checkDuplication");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));

        logger.info("id         : {}", parameterMember.getId());
        logger.info("activateYn : {}", parameterMember.getActivateYn());

        return chattingDayMemberService.checkIdDuplication(parameterMember);
    }

    /**
     * 사용자 등록을 위해서 메일 중복 검사를 한다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/checkMailDuplication")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember checkMailDuplication(InputStream is) throws Exception {
        logger.info("checkMailDuplication");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setMail(jsonMember2.getString("mail"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));

        logger.info("mail       : {}", parameterMember.getMail());
        logger.info("activateYn : {}", parameterMember.getActivateYn());

        return chattingDayMemberService.checkMailDuplication(parameterMember);
    }

    /**
     * 사용자를 등록 한다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/registerMember")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember registerMember(InputStream is) throws Exception {
        logger.info("registerMember");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setOpenIdYn(jsonMember2.getString("openIdYn"));
        parameterMember.setPassword(jsonMember2.getString("password"));
        parameterMember.setNickName(jsonMember2.getString("nickName"));
        parameterMember.setOpenNickNameYn(jsonMember2.getString("openNickNameYn"));
        parameterMember.setGender(jsonMember2.getString("gender"));
        parameterMember.setOpenGenderYn(jsonMember2.getString("openGenderYn"));
        parameterMember.setBirthday(jsonMember2.getString("birthday"));
        parameterMember.setOpenBirthdayYn(jsonMember2.getString("openBirthdayYn"));
        parameterMember.setAges(jsonMember2.getString("ages"));
        parameterMember.setOpenAgesYn(jsonMember2.getString("openAgesYn"));
        parameterMember.setMail(jsonMember2.getString("mail"));
        parameterMember.setOpenMailYn(jsonMember2.getString("openMailYn"));
        parameterMember.setCountry(jsonMember2.getString("country"));
        parameterMember.setOpenCountryYn(jsonMember2.getString("openCountryYn"));
        parameterMember.setLanguage(jsonMember2.getString("language"));
        parameterMember.setOpenLanguageYn(jsonMember2.getString("openLanguageYn"));
        parameterMember.setProfileImageUrl(jsonMember2.getString("profileImageUrl"));
        parameterMember.setOpenProfileImageYn(jsonMember2.getString("openProfileImageYn"));
        parameterMember.setLatitude(jsonMember2.getString("latitude"));
        parameterMember.setLongitude(jsonMember2.getString("longitude"));
        parameterMember.setOpenLocationYn(jsonMember2.getString("openLocationYn"));
        parameterMember.setDistance(jsonMember2.getString("distance"));
        parameterMember.setOpenDistanceYn(jsonMember2.getString("openDistanceYn"));
        parameterMember.setFacebookId(jsonMember2.getString("facebookId"));
        parameterMember.setOpenFacebookIdYn(jsonMember2.getString("openFacebookIdYn"));
        parameterMember.setTwitterId(jsonMember2.getString("twitterId"));
        parameterMember.setOpenTwitterIdYn(jsonMember2.getString("openTwitterIdYn"));
        parameterMember.setMileage(jsonMember2.getString("mileage"));
        parameterMember.setOpenMileageYn(jsonMember2.getString("openMileageYn"));
        parameterMember.setGrade(jsonMember2.getString("grade"));
        parameterMember.setOpenGradeYn(jsonMember2.getString("openGradeYn"));
        parameterMember.setLogStatus(jsonMember2.getString("logStatus"));
        parameterMember.setOpenLogStatusYn(jsonMember2.getString("openLogStatusYn"));
        parameterMember.setChatStatus(jsonMember2.getString("chatStatus"));
        parameterMember.setOpenChatStatusYn(jsonMember2.getString("openChatStatusYn"));
        parameterMember.setRestrictionCount(jsonMember2.getString("restrictionCount"));
        parameterMember.setRestrictionYn(jsonMember2.getString("restrictionYn"));
        parameterMember.setDeviceType(jsonMember2.getString("deviceType"));
        parameterMember.setRegistrationId(jsonMember2.getString("registrationId"));
        parameterMember.setInstallYn(jsonMember2.getString("installYn"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));
        parameterMember.setModifyDate(jsonMember2.getString("modifyDate"));
        parameterMember.setRegisterDate(jsonMember2.getString("registerDate"));

        ChattingDayMember resultMember = new ChattingDayMember();

        if(chattingDayMemberService.registerMember(parameterMember)) {
            resultMember.setResult("SUCCESS");
        } else {
            resultMember.setResult("FAIL");
        }

        return resultMember;
    }

    /**
     * 사용자 정보를 가져 온다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/selectMemberInformation")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember selectMemberInformation(InputStream is) throws Exception {
        logger.info("selectMemberInformation");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setPassword(jsonMember2.getString("password"));

        logger.info("id         : {}", parameterMember.getId());
        logger.info("activateYn : {}", parameterMember.getActivateYn());

        return chattingDayMemberService.selectMemberInformation(parameterMember);
    }

    /**
     * 사용자 로그인을 한다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/login")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember login(InputStream is) throws Exception {
        logger.info("login");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setPassword(jsonMember2.getString("password"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));

        logger.info("id         : {}", parameterMember.getId());
        logger.info("password   : {}", parameterMember.getPassword());
        logger.info("activateYn : {}", parameterMember.getActivateYn());

        return chattingDayMemberService.login(parameterMember);
    }

    /**
     * 사용자 목록을 가져 온다.
     *
     * 추후 마무리 할 것.
     *
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/selectMemberList")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public List<ChattingDayMember> selectMemberList(InputStream is) throws Exception {
        logger.info("updateMemberInformation");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        return chattingDayMemberService.selectMemberList(parameterMember);
    }

    /**
     * 사용자 정보를 수정 한다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateMemberInformation")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember updateMemberInformation(InputStream is) throws Exception {
        logger.info("updateMemberInformation");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setOpenIdYn(jsonMember2.getString("openIdYn"));
        parameterMember.setPassword(jsonMember2.getString("password"));
        parameterMember.setNickName(jsonMember2.getString("nickName"));
        parameterMember.setOpenNickNameYn(jsonMember2.getString("openNickName"));
        parameterMember.setGender(jsonMember2.getString("gender"));
        parameterMember.setOpenGenderYn(jsonMember2.getString("openGenderYn"));
        parameterMember.setBirthday(jsonMember2.getString("birthday"));
        parameterMember.setOpenBirthdayYn(jsonMember2.getString("openBirthdayYn"));
        parameterMember.setAges(jsonMember2.getString("ages"));
        parameterMember.setOpenAgesYn(jsonMember2.getString("openAgesYn"));
        parameterMember.setMail(jsonMember2.getString("mail"));
        parameterMember.setOpenMailYn(jsonMember2.getString("openMailYn"));
        parameterMember.setCountry(jsonMember2.getString("country"));
        parameterMember.setOpenCountryYn(jsonMember2.getString("openCountryYn"));
        parameterMember.setLanguage(jsonMember2.getString("language"));
        parameterMember.setOpenLanguageYn(jsonMember2.getString("openLanguageYn"));
        parameterMember.setProfileImageUrl(jsonMember2.getString("profileImageUrl"));
        parameterMember.setOpenProfileImageYn(jsonMember2.getString("openProfileImageYn"));
        parameterMember.setLatitude(jsonMember2.getString("latitude"));
        parameterMember.setLongitude(jsonMember2.getString("longitude"));
        parameterMember.setOpenLocationYn(jsonMember2.getString("openLocationYn"));
        parameterMember.setDistance(jsonMember2.getString("distance"));
        parameterMember.setOpenDistanceYn(jsonMember2.getString("openDistanceYn"));
        parameterMember.setFacebookId(jsonMember2.getString("facebookId"));
        parameterMember.setOpenFacebookIdYn(jsonMember2.getString("openFacebookIdYn"));
        parameterMember.setTwitterId(jsonMember2.getString("twitterId"));
        parameterMember.setOpenTwitterIdYn(jsonMember2.getString("openTwitterIdYn"));
        parameterMember.setMileage(jsonMember2.getString("mileage"));
        parameterMember.setOpenMileageYn(jsonMember2.getString("openMileageYn"));
        parameterMember.setGrade(jsonMember2.getString("grade"));
        parameterMember.setOpenGradeYn(jsonMember2.getString("openGradeYn"));
        parameterMember.setLogStatus(jsonMember2.getString("logStatus"));
        parameterMember.setOpenLogStatusYn(jsonMember2.getString("openLogStatusYn"));
        parameterMember.setChatStatus(jsonMember2.getString("chatStatus"));
        parameterMember.setOpenChatStatusYn(jsonMember2.getString("openChatStatusYn"));
        parameterMember.setRestrictionCount(jsonMember2.getString("restrictionCount"));
        parameterMember.setRestrictionYn(jsonMember2.getString("restrictionYn"));
        parameterMember.setDeviceType(jsonMember2.getString("deviceType"));
        parameterMember.setRegistrationId(jsonMember2.getString("registrationId"));
        parameterMember.setInstallYn(jsonMember2.getString("installYn"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));
        parameterMember.setModifyDate(jsonMember2.getString("modifyDate"));

        ChattingDayMember resultMember = new ChattingDayMember();

        if(chattingDayMemberService.updateMemberInformation(parameterMember)) {
            resultMember.setResult("SUCCESS");
        } else {
            resultMember.setResult("FAIL");
        }

        return resultMember;
    }

    /**
     * 사용자를 비활성화 한다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateDeactivateMember")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember updateDeactivateMember(InputStream is) throws Exception {
        logger.info("updateDeactivateMember");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));
        parameterMember.setModifyDate(jsonMember2.getString("modifyDate"));

        logger.info("id         : {}", parameterMember.getId());
        logger.info("activateYn : {}", parameterMember.getActivateYn());
        logger.info("modifyDate : {}", parameterMember.getModifyDate());

        ChattingDayMember resultMember = new ChattingDayMember();

        if(chattingDayMemberService.updateDeactivateMember(parameterMember)) {
            resultMember.setResult("SUCCESS");
        } else {
            resultMember.setResult("FAIL");
        }

        return resultMember;
    }

    /**
     * 사용자의 마일리지를 가져 온다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/selectMileage")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember selectMileage(InputStream is) throws Exception {
        logger.info("selectMileage");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));

        logger.info("id         : {}", parameterMember.getId());
        logger.info("activateYn : {}", parameterMember.getActivateYn());

        /**
         * SHA256 테스트 용도. 추 후 삭제 예정.
         */
        logger.info("encryptData : {}", chattingDayCommon.getEncodedPassword(parameterMember.getId()));

        return chattingDayMemberService.selectMileage(parameterMember);
    }

    /**
     * 사용자 마일리지를 수정 한다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateMileage")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember updateMileage(InputStream is) throws Exception {
        logger.info("updateMileage");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setMileage(jsonMember2.getString("mileage"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));
        parameterMember.setModifyDate(jsonMember2.getString("modifyDate"));

        logger.info("id         : {}", parameterMember.getId());
        logger.info("mileage    : {}", parameterMember.getMileage());
        logger.info("activateYn : {}", parameterMember.getActivateYn());
        logger.info("modifyDate : {}", parameterMember.getModifyDate());

        ChattingDayMember resultMember = new ChattingDayMember();

        if(chattingDayMemberService.updateMileage(parameterMember)) {
            resultMember.setResult("SUCCESS");
        } else {
            resultMember.setResult("FAIL");
        }

        return resultMember;
    }

    /**
     * 사용자 벌점을 수정 한다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateRestrictionCount")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember updateRestrictionCount(InputStream is) throws Exception {
        logger.info("updateRestrictionCount");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setRestrictionCount(jsonMember2.getString("restrictionCount"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));
        parameterMember.setModifyDate(jsonMember2.getString("modifyDate"));

        logger.info("id               : {}", parameterMember.getId());
        logger.info("restrictionCount : {}", parameterMember.getRestrictionCount());
        logger.info("activateYn       : {}", parameterMember.getActivateYn());
        logger.info("modifyDate       : {}", parameterMember.getModifyDate());

        ChattingDayMember resultMember = new ChattingDayMember();

        if(chattingDayMemberService.updateRestrictionCount(parameterMember)) {
            resultMember.setResult("SUCCESS");
        } else {
            resultMember.setResult("FAIL");
        }

        return resultMember;
    }

    /**
     * 사용자 사용 제한 여부를 수정 한다.
     *
     * 만약 사용 제한을 하면 count 는 0 으로 초기화 한다.
     *
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateRestrictionStatus")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember updateRestrictionStatus(InputStream is) throws Exception {
        logger.info("updateRestrictionStatus");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setRestrictionCount(jsonMember2.getString("restrictionCount"));
        parameterMember.setRestrictionYn(jsonMember2.getString("restrictionYn"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));
        parameterMember.setModifyDate(jsonMember2.getString("modifyDate"));

        logger.info("id               : {}", parameterMember.getId());
        logger.info("restrictionCount : {}", parameterMember.getRestrictionCount());
        logger.info("restrictionYn    : {}", parameterMember.getRestrictionYn());
        logger.info("activateYn       : {}", parameterMember.getActivateYn());
        logger.info("modifyDate       : {}", parameterMember.getModifyDate());

        ChattingDayMember resultMember = new ChattingDayMember();

        if(chattingDayMemberService.updateRestrictionStatus(parameterMember)) {
            resultMember.setResult("SUCCESS");
        } else {
            resultMember.setResult("FAIL");
        }

        return resultMember;
    }

    /**
     * 사용자의 로그인 상태를 수정 한다.
     *
     * IN/OUT
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateLogStatus")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember updateLogStatus(InputStream is) throws Exception {
        logger.info("updateLogStatus");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setLogStatus(jsonMember2.getString("logStatus"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));
        parameterMember.setModifyDate(jsonMember2.getString("modifyDate"));

        logger.info("id         : {}", parameterMember.getId());
        logger.info("logStatus  : {}", parameterMember.getLogStatus());
        logger.info("activateYn : {}", parameterMember.getActivateYn());
        logger.info("modifyDate : {}", parameterMember.getModifyDate());

        ChattingDayMember resultMember = new ChattingDayMember();

        if(chattingDayMemberService.updateLogStatus(parameterMember)) {
            resultMember.setResult("SUCCESS");
        } else {
            resultMember.setResult("FAIL");
        }

        return resultMember;
    }

    /**
     * 사용자의 채팅방 참석 여부를 수정 한다.
     *
     * ON/OFF
     *
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateChatStatus")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember updateChatStatus(InputStream is) throws Exception {
        logger.info("updateChatStatus");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setChatStatus(jsonMember2.getString("chatStatus"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));
        parameterMember.setModifyDate(jsonMember2.getString("modifyDate"));

        logger.info("id         : {}", parameterMember.getId());
        logger.info("chatStatus : {}", parameterMember.getChatStatus());
        logger.info("activateYn : {}", parameterMember.getActivateYn());
        logger.info("modifyDate : {}", parameterMember.getModifyDate());

        ChattingDayMember resultMember = new ChattingDayMember();

        if(chattingDayMemberService.updateChatStatus(parameterMember)) {
            resultMember.setResult("SUCCESS");
        } else {
            resultMember.setResult("FAIL");
        }

        return resultMember;
    }

    /**
     * 사용자의 Google GCM Registration Id 를 수정 한다.
     * 
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateRegistrationId")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public ChattingDayMember updateRegistrationId(InputStream is) throws Exception {
        logger.info("updateRegistrationId");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonMember = new JSONObject(line);
        JSONObject jsonMember2 = jsonMember.getJSONObject("chattingDayMember");

        ChattingDayMember parameterMember = new ChattingDayMember();

        parameterMember.setId(jsonMember2.getString("id"));
        parameterMember.setRegistrationId(jsonMember2.getString("registrationId"));
        parameterMember.setActivateYn(jsonMember2.getString("activateYn"));
        parameterMember.setModifyDate(jsonMember2.getString("modifyDate"));

        logger.info("id             : {}", parameterMember.getId());
        logger.info("registrationId : {}", parameterMember.getRegistrationId());
        logger.info("activateYn     : {}", parameterMember.getActivateYn());
        logger.info("modifyDate     : {}", parameterMember.getModifyDate());

        ChattingDayMember resultMember = new ChattingDayMember();

        if(chattingDayMemberService.updateRegistrationId(parameterMember)) {
            resultMember.setResult("SUCCESS");
        } else {
            resultMember.setResult("FAIL");
        }

        return resultMember;
    }
}
